# -*- coding;utf-8 -*-
"""
File name : main.py.PY
Program IDE : PyCharm
Create file time: 2023/10/17 7:59
File Create By Author : 朱清闯
"""
import os
from django.conf import settings
from celery import Celery

if not os.getenv('DJANGO_SETTINGS_MODULE'):
    # 设置 添加 Django项目 的 setting 路径 到 os 环境变量
    os.environ['DJANGO_SETTINGS_MODULE'] = 'questionBank.settings'  # 要对应 自己的 Django 项目名
redis_database = settings.REDIS_DATABASE['CELERY_BACKEND']
backend = f'redis://:{redis_database["PASSWORD"]}@{redis_database["HOST"]}:{redis_database["PORT"]}/{redis_database["DB"]}'
app = Celery("questionBank", backend=backend)
# password = redis_database.get('PASSWORD', '')
# if not password:
#     backend = f'redis://:@{redis_database["HOST"]}:{redis_database["PORT"]}/{redis_database["DB"]}'
# else:
#     backend = f'redis://:{redis_database["PASSWORD"]}@{redis_database["HOST"]}:{redis_database["PORT"]}/{redis_database["DB"]}'
# app = Celery("demo", backend=backend)

app.config_from_object('celery_tasks.celery_config', namespace='CELERY')
# app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks(['celery_tasks.notification', 'celery_tasks.bankpoint', 'celery_tasks.download'])

